package com.diaohw.platform.framework.swagger;

import cn.hutool.core.net.NetUtil;
import cn.hutool.extra.spring.SpringUtil;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Hello world!
 */
@Slf4j
@Configuration
public class SwaggerConfig {
    @Resource
    SwaggerProperties swaggerProperties;

    @PostConstruct
    public void initial() {
        String port = SpringUtil.getProperty("server.port");
        System.out.println("\n========================= swagger 文档 start =========================");
        for (String ip : NetUtil.localIpv4s()) {
            System.out.printf("http://%s:%s/doc.html\n", ip, port);
        }
        System.out.println("========================== swagger 文档 end ==========================\n");
    }

    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title(swaggerProperties.getTitle())
                        .version(swaggerProperties.getVersion())
                        .contact(swaggerProperties.getContact())
                        .description(swaggerProperties.getDescription())
                        .summary(swaggerProperties.getSummary())
                );
    }


}
